
/*
 * jQuery Admin Plus @requires jQuery v1.4+
 * Dual licensed under the MIT and GPL licenses.
 *
 * Autor: Leo
 * Version: 3.2
 */
 ;(function(){
    var tag2attr = {
        a       : 'href',
        img     : 'src',
        form    : 'action',
        base    : 'href',
        script  : 'src',
        iframe  : 'src',
        link    : 'href'
    },
    
	key = ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","fragment"], // keys available to query
	
	aliases = { "anchor" : "fragment" }, // aliases for backwards compatability

	parser = {
		strict  : /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,  //less intuitive, more accurate to the specs
		loose   :  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
	},
	
	querystring_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g, // supports both ampersand and semicolon-delimted query string key/value pairs
	
	fragment_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g; // supports both ampersand and semicolon-delimted fragment key/value pairs
	
	function parseQuery( query )
	{
		if(query==undefined||query=='') return {};
		
		var str = decodeURI( query ),
		    $query = {},
			querystring_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g;
		
		str.replace( querystring_parser, function ( $0, $1, $2 ){
			if ($1)
			{
				$query[$1] = $2;
			}
		});
		return $query
	};
	
	function getAttrName( elm )
	{
		var tn = elm.tagName;
		if ( tn !== undefined ) return tag2attr[tn.toLowerCase()];
		return tn;
	}
	
	$.querystring = function( query )
	{
		
        this.basedata = parseQuery(window.location.search.substring(1));

        return {
            
			data : $.extend({},this.basedata,parseQuery(query)),
			
            attr : function( param )
            {
				return param !== undefined ? this.data[param] : this.data;
                //return param !== undefined ? this.data.param[param] : this.data.param;
            },
			toString : function(){
				return $.param(this.data);
			}   
        };
        
	};
	$.fn.extend({
		wresize : function( f ){
			version = '1.1';
			wresize = {fired: false, width: 0};
	
			function resizeOnce() 
			{
				if ( $.browser.msie )
				{
					if ( ! wresize.fired )
					{
						wresize.fired = true;
					}
					else 
					{
						var version = parseInt( jQuery.browser.version, 10 );
						wresize.fired = false;
						if ( version < 7 )
						{
							return false;
						}
						else if ( version == 7 )
						{
							//a vertical resize is fired once, an horizontal resize twice
							var width = $( window ).width();
							if ( width != wresize.width )
							{
								wresize.width = width;
								return false;
							}
						}
					}
				}
	
				return true;
			}
	
			function handleWResize( e ) 
			{
				if ( resizeOnce() )
				{
					return f.apply(this, [e]);
				}
			}
	
			this.each( function() 
			{
				if ( this == window )
				{
					$( this ).resize( handleWResize );
				}
				else
				{
					$( this ).resize( f );
				}
			} );
	
			return this;
		},
		insertHtml : function (str) {
			$(this).focus();
			var obj = $(this).get(0);
			if (document.selection) {
				var sel = document.selection.createRange();
				sel.text = str;
			} else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
				var startPos = obj.selectionStart,
					endPos = obj.selectionEnd,
					cursorPos = startPos,
					tmpStr = obj.value;
				obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
				cursorPos += str.length;
				obj.selectionStart = obj.selectionEnd = cursorPos;
			} else {
				obj.value += str;
			}
		},
		loadContent: function(fCmd,opts){
			opts = opts || {};
			return this.each(function(n,el){
				$el = $(el);
				opts.async = false;
				opts.complete=function(xhr){
						$el.html(xhr.responseText);
					};
				$.doCmd(fCmd,opts)
			});

		}
		
	});
	$.extend({
		loadContent: function(el,fCmd,opts){
			$(el).loadContent(fCmd,opts);
		},
		charLen : function(s){
			return s.replace(/[^\x00-xff]/g,"**").length;
		},
		moveOptions : function(_source,_target,_copy){
			$('#'+_source).find("option:selected").each(function(n,el){
				if(_target!=null){
					if($('#'+_target).find('option[value='+$(this).val()+']').length<=0)
						$('#'+_target).append('<option value="'+$(this).val()+'">'+$(this).html()+'</option>');
				}
				if(_copy==0)$(this).remove()
			})
		},
		mutiOptions : function(_source){
			var rtnValue =''
			$('#'+_source+ ' option').each(function(){this.selected=true;})
			return rtnValue;
		},
		
		getCheckbox : function(checkbox,bAlert){
			var rtnValue = '';
			$('input[name='+checkbox+']').each(function(){	
				if(this.checked&&!this.disabled){
					rtnValue+=this.value+',';
				}})
			if(rtnValue==''&&bAlert) alert("请至少选择一个记录");
			return ((rtnValue=='')?false:rtnValue);
		},
　　		doCmd : function(fCmd,opts){
			opts = opts || {};
			isConfirm = opts.confirm || false;
			query = opts.query || '';
			var rtnValue = false
			/* CheckBox */
			if(opts.checkbox!=null){
				var returnVal = $.getCheckbox(opts.checkbox);
				if(!returnVal){
					alert("请至少选择一个记录");
					return;
				}
				query += '&'+opts.checkbox+'='+returnVal;
			}
			
			if(fCmd.indexOf('删除')>-1) isConfirm = true;
			title = opts.title || fCmd;
			if(isConfirm){
				if(!window.confirm('您是否确定['+title+']？'))
				return false;
			}
			
			if(opts.button)$(opts.button).attr('disabled',true)
			
			
			method = opts.method || 'get';
			if(method=='post'){
				var url = location.pathname+'?f='+encodeURI(fCmd);
			}else{
				var url = location.pathname;
				query = 'f='+encodeURI(fCmd)+'&'+query+'&'+Math.random();
			}		
			var bAlert = opts.alert || false,
				docomplete = opts.complete || function(xhr){
					$._result(xhr.responseText,opts.success,opts.error || alert)
				}
			$.ajax({
				type:method,
				async:(opts.async||false),
				beforeSend : function(xhr){	xhr.setRequestHeader("HTTP_X_XMLHTTP_MODE", "true"); },
				url:url,
				data: query,
				complete:docomplete		
				})
			if(opts.button)$(opts.button).attr('disabled',false)
			return rtnValue;
		},
		_result : function(fC,callback){
			if(!fC){alert("提交服务器操作失败,请联系管理员!!!     ");return false;}
			var code = fC.split(",")[0] ;		//返回的代码
			var message = fC.split(",")[1] ;	//返回的信息
			var value = fC.split(",")[2];		//附加值,用于表单验证,返回input 的ID
			try{
				switch (code){
					case '1':
					case '2':
						var info= message || "操作成功!!!";
						//if(message && message.length>0) info = message;
						//是否回显提示
						if($.isFunction(callback))	callback(code,info);
						return true;
						break;
					case '101':
						if(message){
							alert(message + "("+ code + ")");
						}else{
							alert(code);
						}
						/*if(value&& $(value)) $(value).focus();*/
						return false;
					case '102':
						alert('找不到此更新的内容！！！('+code+')');
						return false;
					case '103': 
						alert('验证码填写出错，请检查！！！('+code+')');
						return false;
						break;
					case '403': 
						alert('您还未登录或是登录超时！！！('+code+')');
						return false;
						break;
					default:
						if(message){
							alert(message + "("+ code + ")");
						}else{
							alert(code);
						}
						return false;
				}
			}catch(e){alert(e.message);}
			return false;
	}
	}); 
	
	/*
	** TabManage V2.6**
	*/
	var tabId = 0;
	function getNextTabId() {
		return ++tabId;
	}
	TabManage = function(el,o){
		this.element = $(el);
		this.options = $.extend(this.options,o);
		this._create()
	}
	$.extend(TabManage.prototype,{
		options: {
			add: null,
			ajaxOptions: null,
			cache: false,
			tabClass : '.tabgroup .tab',
			panelClass:'.contentgroup .content',
			cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
			collapsible: false,
			disable: null,
			disabled: [],
			enable: null,
			event: "click",
			fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
			idPrefix: "tab",
			load: null,
			remove: null,
			select: null,
			show: null,
			spinner: "<em>Loading&#8230;</em>",
			tabTemplate: '<li><span class="title">{label}</span></li>',
			panelTemplate: '<div></div>'
		},
		templates :[],
		selectedIndex : 0 ,
		_gettabs:function(){
			return $(this.options.tabClass,this.element);
		},
		_getpanels:function(){
			return $(this.options.panelClass,this.element);
		},
		_create: function() {
			this._gettabs().each($.proxy(function(index,el){
				var _name = $.trim($(el).text()),
					_title = el.title || _name ,
					jsonobj = this.add({name:_name,title:_title,allowclose:false}),
					_content = _id+'_content';
				el.id = jsonobj.id
				$(el).bind(this.options.event,this,function(e){
					e.data.selectTab(this.id)
				})
				this._getpanels().each(function(idx, element) {
					if(idx ==index) this.id = _content;
				});
			},this))
			this.select(this.options.selected || this.selectedIndex);
		},
		_getIndex : function(id){
			for(var i=0;i<this.templates.length;i++){
				if(this.templates[i].id==id) return i;
			};
			return -1
		},
		_cookie: function() {
			var cookie = this.cookie ||
				( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
			return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
		},
		add : function(jsonobj){
			jsonobj = $.extend({
					id : this.options.idPrefix+ getNextTabId(),
					page:1,
					query:'',
					isload:0,
					parentid : (this.templates.length!=0)?this.templates[this.selectedIndex].id:null,
					allowclose: true
				},jsonobj)
				
			_id =  jsonobj.id;
			_parentid = jsonobj.parentid;
			var _title = jsonobj.title || jsonobj.name;
			
			if($(this.element).has('#'+_parentid)){
				$(this.options.tabTemplate.replace(/\{label\}/ig,_title)).addClass('tab').attr("id",_id)
				.bind(this.options.event,this,function(e){
					e.data.selectTab(this.id)
				})
				.insertAfter('#'+_parentid)
				
				$(this.options.panelTemplate).addClass('content').attr("id",_id+'_content')
				.insertAfter('#'+_parentid+'_content');
			}
			
			if(jsonobj.allowclose){
				$('<a href="###"> </a>').addClass('close').click(this,function(e){
					e.stopPropagation();
					if(window.confirm('确定关闭('+_title+')？ ')){
						e.data.closeTab($(this).parent().attr('id'));
						return false;
					}
				}).appendTo('#'+_id)
			}
			index = this.templates.push(jsonobj);
			
			this.selectedIndex  = index-1;
			
			$('#tabScroll').width('100%')
			return jsonobj;
		},
		select : function(index){
			if(index==null||index>=this.templates.length)
				return ;
				
			this.selectedIndex = index;
			
			if(!this.templates[index].isload){ 
				this.tList()
			}else{
				this.show(this.templates[index].id);
			}
			if(typeof this.options.select=='function')	this.options.select(index);
		},
		selectTab : function(id){
			this.select(this._getIndex(id));
		},
		show : function(id){
			this._gettabs().removeClass('current')
			$('#'+id).addClass('current');
			
			this._getpanels().hide()
			$('#'+id+'_content').show();
			
			$('#closeTab').toggle(this.templates[this._getIndex(id)].allowclose);
			
			if(typeof this.options.show=='function') this.options.show(id);
		},
		switchClass : function(el,oldClass,newClass){
			
		},
		tList: function(page,query,Asyn){
			index = this.selectedIndex;
			if(page>0) this.templates[index].page = page;
			if(query) this.templates[index].query = query;
			
			var temp = this.templates[index],
				$content = $('#'+temp.id+'_content'),
				loadfunction = this.options.load,
				q = 'f='+encodeURI(temp.name) + '&page=' + temp.page +'&' + (temp.query || '')+'&'+Math.random()+'&__templateid='+temp.id
				
			$content
			.ajaxSend(function(e, xhr) {
				xhr.setRequestHeader("HTTP_X_XMLHTTP_MODE", "true");})
			.load(location.pathname,q,function(){
				temp.isload = true;
				if(typeof loadfunction=='function') loadfunction(this);
			});
			this.templates[index].isload = true;
			this.templates[index].content = $content;
			
			this.show(this.templates[index].id);
		},
		pList: function(){
			this.closeTab();
			this.tList();
		},
		tQuery: function(query){
			this.tList(1,query);
		},
		reload : function(){
			this.tList()
		},
		openTab : function(name,query,title){
			this.add({'name':name,'query':query,'title':title});
			this.select(this.selectedIndex);
		},
		childTabs: function(id){
			return $(this.templates).filter(function() {
				return this.parentid==id
			})
		},
		closeTab: function(id){
			
			index = (id&&(i=this._getIndex(id))!=-1)?i:this.selectedIndex
			
			var temp = this.templates[index],
				id = this.templates[index].id,
				parentid = this.templates[index].parentid

			if(temp.allowclose){
				var $childs = this.childTabs(id),
					icount = $childs.size()		
							
				if(icount>0){
					if(!window.confirm('此选项卡(含有'+icount+'个子选项卡)，关闭此将关闭所有全部子选项卡,\n是否确认关闭？'))return ;
					$childs.each($.proxy(function(n,self){
						this.closeTab(self.id)
					},this))
				}
				$('#'+temp.id).remove()
				$('#'+temp.id+'_content').remove()
				this.templates = $(this.templates).not(function(){
					return this.id == temp.id
					}).toArray();
				this.selectTab(parentid)
			}
		},
		openHtml: function(divid,inputid,height){
			var fckid = this.templates[this.selectedIndex].id+'_'+inputid;
			var oEditor = new FCKeditor(fckid,null,height,'Admin') ;
			oEditor.Value = this.get('#'+inputid).val();
			this.get('#'+divid).html(oEditor.CreateHtml())
		},
		GetContents: function(inputid){
			var fckid = this.templates[this.selectedIndex].id+'_'+inputid;
			var oEditor = FCKeditorAPI.GetInstance(fckid); 
			this.get('#'+inputid).val(oEditor.GetXHTML(true));
		},
		doCheckBoxCmd: function(fName,checkboxid,val){
			return $.doCmd(fName,{'checkbox':checkboxid,query:'status='+(val||''),success:function(){rtnValue = true;}});
		},
		get:function(css){
			return this.templates[this.selectedIndex].content.find('#'+css);
		},
		CheckBoxSelect : function(checkboxid,flag){
			var $content = this.templates[this.selectedIndex].content;
				$('input:checkbox:enabled[name='+checkboxid+']',$content).each(function(){
					this.checked = (flag==2)?!this.checked:flag;
				})
		},
		doCmd:function(/*String*/fCmd,opts){
			return $.doCmd(fCmd,opts);
		},
		saveContentCmd:function(sForm,opts){
			
			var $content = this.templates[this.selectedIndex].content,
				sForm = (sForm.substring(0,1)=='#')?sForm:('#'+sForm),
				q= $content.find(sForm).serialize(),
				rtnValue = false,
				isalert = opts.alert
			try{
				if(opts.button) $content.find('#'+opts.button).attr('disabled',true)
				$.ajax({
					type:'post',
					url:'/aspx/cityflypost.aspx',
					data: q,
					async : false,
					complete:function(xhr){
						rtnValue = $._result(xhr.responseText,function(code,info){
							if(isalert) alert(info)
						})
					}				
					})
					
				return rtnValue;
			}catch(e){
				alert(e)
			}
			if(opts.button) $content.find('#'+opts.button).attr('disabled',false)
			return false;
			
		},
		length: function() {
			return this.templates.length;
		}
	});
})(jQuery);

Date.prototype.format = function(mask) {  
  
    var d = this;  
  
    var zeroize = function (value, length) {  
  
        if (!length) length = 2;  
  
        value = String(value);  
  
        for (var i = 0, zeros = ''; i < (length - value.length); i++) {  
  
            zeros += '0';  
  
        }  
  
        return zeros + value;  
  
    };    
  
    return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function($0) {  
  
        switch($0) {  
  
            case 'd':   return d.getDate();  
  
            case 'dd':  return zeroize(d.getDate());  
  
            case 'ddd': return ['Sun','Mon','Tue','Wed','Thr','Fri','Sat'][d.getDay()];  
  
            case 'dddd':    return ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][d.getDay()];  
  
            case 'M':   return d.getMonth() + 1;  
  
            case 'MM':  return zeroize(d.getMonth() + 1);  
  
            case 'MMM': return ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][d.getMonth()];  
  
            case 'MMMM':    return ['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];  
  
            case 'yy':  return String(d.getFullYear()).substr(2);  
  
            case 'yyyy':    return d.getFullYear();  
  
            case 'h':   return d.getHours() % 12 || 12;  
  
            case 'hh':  return zeroize(d.getHours() % 12 || 12);  
  
            case 'H':   return d.getHours();  
  
            case 'HH':  return zeroize(d.getHours());  
  
            case 'm':   return d.getMinutes();  
  
            case 'mm':  return zeroize(d.getMinutes());  
  
            case 's':   return d.getSeconds();  
  
            case 'ss':  return zeroize(d.getSeconds());  
  
            case 'l':   return zeroize(d.getMilliseconds(), 3);  
  
            case 'L':   var m = d.getMilliseconds();  
  
                    if (m > 99) m = Math.round(m / 10);  
  
                    return zeroize(m);  
  
            case 'tt':  return d.getHours() < 12 ? 'am' : 'pm';  
  
            case 'TT':  return d.getHours() < 12 ? 'AM' : 'PM';  
  
            case 'Z':   return d.toUTCString().match(/[A-Z]+$/);  
  
            // Return quoted strings with the surrounding quotes removed  
  
            default:    return $0.substr(1, $0.length - 2);  
  
        }  
  
    }); 
}; 